<script type="text/javascript" SRC="/js/merchant/warehouseproducts.js"></script>
<script type="text/javascript">
$(function(){
	initData(0); //初始化分页数据
	
	$("#tipDialog").dialog({
		autoOpen:false,
		modal:true,
		width:300,
		show:"slide",
		buttons:{
			"Close":function(){
				$(this).dialog("close");
				clear();
			}
		}
	});
	receivingProduct(<{$receiving_id}>);
});


function sumbitForm(){
    var formData =$('#editForm').serialize();
	$.ajax({
		type: "POST",
		async: false,
		dataType: "json",
		url: "/merchant/returns/create",
		data:formData,
		success: function(json) {
			var html ="";
            if(json.ask==1){
                $("#tipDialog").html('ASNNo: '+json.receiving_code+' Edit success!');
                
            }else{
                var html = "";
				$.each(json.error,function(k,v){
					html += v+"<br/>";
				});
				$("#tipDialog").html(html);
            }
            $("#tipDialog").dialog("open");
		}
	});
}

function clear(){
	$('[name=reference_no]').val('');
	$('[name=instructions]').val('');
	$('#ProductList').html('');
	$('.all_weight').html('');
}

function checkAll(obj){
	if(jQuery (obj).attr("checked")=='checked'){
		jQuery ('.checked').attr('checked',true);
	}else{
	    jQuery ('.checked').attr('checked',false);
	}
}

function receivingProduct(receiving_id) {
	
	$.ajax({
		type: "POST",
		async: false,
		dataType: "json",
		url: "/merchant/receiving/receiving-product",
		data:{
           	'receiving_id':receiving_id
		},
		success: function(json) {
			var html = '';
			if(json.ask != 1) {
				html = '<div class="line1">&nbsp;No data returns</div>';
			}else {
										
				$.each(json.result,function(k,v){
					html += '<div class="row height25 productRow'+v.product_id+'">';
					html += '<div class="cell" style="width:20%">'+v.product_sku+'</div>';
					html += '<div class="cell" style="width:24%">'+v.product_title+'</div>';
					html += '<div class="cell" style="width:20%">'+v.category.poc_value+'</div>';
					html += '<div class="cell" style="width:15%"><input type="text" class="inputText" name="op_quantity[]" value="'+v.order_qty+'" style="width:80px;text-align:right" id="op_quantity'+v.product_id+'"  onblur="calWeihgt()"/></div>';
					html += '<div class="cell" style="width:10%" id="product_weight'+v.product_id+'">'+v.product_weight+'</div>';
					html +='<div class="cell" style="width:10%; padding-top:5px;"><img src="/images/icon_del.gif" name="button'+v.product_sku+'" onclick="deleteProduct(this)" class="cursor" title="Delete"/><input type="hidden"  name="product_id[]" class ="product_id" value="'+v.product_id+'" /><input type="hidden"  name="op_id[]" value="0" /></div>';
					html += '<div class="clearFloat"></div>';
					html += '</div>';
				});	
				$('#reference_no').val(json.receiving.ref_id);
				$('[name=instructions]').val(json.receiving.description);
				$('[name=receiving_id]').val(json.receiving.receiving_id);
			}
			$('#ProductList').append(html);	
			calWeihgt();		
		}	//success
	});

}


</script>
<div class="position"><a>Merchant Center</a> > <a>Operations</a> > RMA Edit</div>

<form id="editForm"  method="POST" >

<div style="margin-bottom:10px">

</div>

<div class="tab-div">

	<div class="row">
		<div class="right"  style="width:20%;padding-left: 5px; font-size:14px;font-weight:bold">Reciving List:</div>
		<div class="middle">			
			<span class="button-2"  onclick="OpenProductDiv()">Add Product</span>
			<span class="red">&nbsp;&nbsp;</span>
		</div>
		<div class="right"></div>
	</div>
	
	<div class="row "  id="OrderProduct">
		<div class="row height25 row-header">
			<div class="cell sort" style="width:20%" >SKU</div>
			<div class="cell sort" style="width:24%" >SKU Name</div>
			<div class="cell sort" style="width:20%" >Category</div>
			<div class="cell sort" style="width:15%" >Quantity</div>
			<div class="cell sort" style="width:10%" >Weight</div>
			<div class="cell no-background" style="width:10%">Action</div>
		</div>
		<div id="ProductList"  class="row"></div>
	</div>
	
	<div class="row height25">
		<div class="cell" style="width:80%;text-align:right" >Total Weight &nbsp; </div>
		<div class="cell all_weight"  style="width:20%;text-align:left" ></div>
	</div>

</div>

<h4>Additional Info</h4>
<div class="tab-div">
    <div class="row">
		<div class="right"  style="width:20%;padding-left:5px;padding-top:10px">Reference No.</div>
    	<div class="middle">
    		<span id="reference_no"></span>
    		<span class="red">&nbsp;&nbsp;</span>
    	</div>
    	<div class="right"></div>
	</div>

	<div class="row" style="padding-left:5px;padding-top:5px">
		<div class="right"  style="width:20%;height:95px;">Special Instructions:</div>
    	<div class="middle">
    		<textarea cols="38" rows="5" name="instructions" ></textarea>
			<input type="hidden" name="receiving_id" value="" />	<!-- receiving_id，修改状态时不为空-->
    		<span class="red">&nbsp;&nbsp;</span>
    	</div>
    	<div class="right"></div>
	</div>
    
    <div class="row" style="height:40px;align:center">

    	<div style="margin-top:10px;margin-left:150px">
    		<span class="button-2"  onclick="sumbitForm()"> Edit </span>    			
    	</div>
    </div>
</div>
</form>

<div class="prdouctDiv" style="display:none" title="Product List">
<{include file='merchant/orders/warehouse-products-list.tpl'}>
</div>

<div id="tipDialog" style="display:none" title="Tip"></div>